import 'package:enter_prise_web/util/MyDio.dart';
import 'package:get/get.dart';

class MainController extends GetxController {
  final MyDio myDio = MyDio();

  List users = [];
  List workRecordOfToday = [];
  @override
  void onInit() {
    super.onInit();
    getUserList();
    getTodayWorkRecord();
  }

  void getUserList() async {
    users.clear();
    var response = await myDio
        .requestData("/attendance/getCominRecent?offset=0", method: "GET");

    if (response.statusCode == 200) {
      if (response.data['data'] != []) {
        response.data['data'].asMap().forEach((key, value) {
          users.add(value);
        });
      }
    }
    //刷新成功
    update(['userlist']);
  }

  void getTodayWorkRecord() async {
    var response = await myDio.requestData("/workRecord/selectToday",
        method: "GET", params: {"offset": 0, "len": 1});
    if (response.statusCode == 200) {
      workRecordOfToday = response.data['works'];
      update(['workRecordToday']);
    }
  }

  void refreshData() {
    getTodayWorkRecord();
  }

  void refreshUserList() {
    getUserList();
  }
}
